/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package REA.impl;

import REA.PolicyRelationshipType;
import REA.REAAttribute;
import REA.REAOperationalEntity;
import REA.REAPackage;
import REA.REAPolicyEntity;
import REA.REAPolicyRelation;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Policy Relation</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link REA.impl.REAPolicyRelationImpl#getOperationalEntity <em>Operational Entity</em>}</li>
 *   <li>{@link REA.impl.REAPolicyRelationImpl#getPolicyEntity <em>Policy Entity</em>}</li>
 *   <li>{@link REA.impl.REAPolicyRelationImpl#getPolicyRelationshipType <em>Policy Relationship Type</em>}</li>
 *   <li>{@link REA.impl.REAPolicyRelationImpl#getAttributes <em>Attributes</em>}</li>
 *   <li>{@link REA.impl.REAPolicyRelationImpl#getName <em>Name</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class REAPolicyRelationImpl extends REAelementImpl implements REAPolicyRelation {
	/**
	 * The cached value of the '{@link #getOperationalEntity() <em>Operational Entity</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getOperationalEntity()
	 * @generated
	 * @ordered
	 */
	protected REAOperationalEntity operationalEntity;

	/**
	 * The cached value of the '{@link #getPolicyEntity() <em>Policy Entity</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPolicyEntity()
	 * @generated
	 * @ordered
	 */
	protected REAPolicyEntity policyEntity;

	/**
	 * The default value of the '{@link #getPolicyRelationshipType() <em>Policy Relationship Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPolicyRelationshipType()
	 * @generated
	 * @ordered
	 */
	protected static final PolicyRelationshipType POLICY_RELATIONSHIP_TYPE_EDEFAULT = PolicyRelationshipType.TYPIFICATION;

	/**
	 * The cached value of the '{@link #getPolicyRelationshipType() <em>Policy Relationship Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPolicyRelationshipType()
	 * @generated
	 * @ordered
	 */
	protected PolicyRelationshipType policyRelationshipType = POLICY_RELATIONSHIP_TYPE_EDEFAULT;

	/**
	 * The cached value of the '{@link #getAttributes() <em>Attributes</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAttributes()
	 * @generated
	 * @ordered
	 */
	protected EList<REAAttribute> attributes;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected REAPolicyRelationImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return REAPackage.Literals.REA_POLICY_RELATION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public REAOperationalEntity getOperationalEntity() {
		if (operationalEntity != null && operationalEntity.eIsProxy()) {
			InternalEObject oldOperationalEntity = (InternalEObject)operationalEntity;
			operationalEntity = (REAOperationalEntity)eResolveProxy(oldOperationalEntity);
			if (operationalEntity != oldOperationalEntity) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, REAPackage.REA_POLICY_RELATION__OPERATIONAL_ENTITY, oldOperationalEntity, operationalEntity));
			}
		}
		return operationalEntity;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public REAOperationalEntity basicGetOperationalEntity() {
		return operationalEntity;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setOperationalEntity(REAOperationalEntity newOperationalEntity) {
		REAOperationalEntity oldOperationalEntity = operationalEntity;
		operationalEntity = newOperationalEntity;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, REAPackage.REA_POLICY_RELATION__OPERATIONAL_ENTITY, oldOperationalEntity, operationalEntity));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public REAPolicyEntity getPolicyEntity() {
		if (policyEntity != null && policyEntity.eIsProxy()) {
			InternalEObject oldPolicyEntity = (InternalEObject)policyEntity;
			policyEntity = (REAPolicyEntity)eResolveProxy(oldPolicyEntity);
			if (policyEntity != oldPolicyEntity) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, REAPackage.REA_POLICY_RELATION__POLICY_ENTITY, oldPolicyEntity, policyEntity));
			}
		}
		return policyEntity;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public REAPolicyEntity basicGetPolicyEntity() {
		return policyEntity;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPolicyEntity(REAPolicyEntity newPolicyEntity) {
		REAPolicyEntity oldPolicyEntity = policyEntity;
		policyEntity = newPolicyEntity;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, REAPackage.REA_POLICY_RELATION__POLICY_ENTITY, oldPolicyEntity, policyEntity));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PolicyRelationshipType getPolicyRelationshipType() {
		return policyRelationshipType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPolicyRelationshipType(PolicyRelationshipType newPolicyRelationshipType) {
		PolicyRelationshipType oldPolicyRelationshipType = policyRelationshipType;
		policyRelationshipType = newPolicyRelationshipType == null ? POLICY_RELATIONSHIP_TYPE_EDEFAULT : newPolicyRelationshipType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, REAPackage.REA_POLICY_RELATION__POLICY_RELATIONSHIP_TYPE, oldPolicyRelationshipType, policyRelationshipType));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<REAAttribute> getAttributes() {
		if (attributes == null) {
			attributes = new EObjectContainmentEList<REAAttribute>(REAAttribute.class, this, REAPackage.REA_POLICY_RELATION__ATTRIBUTES);
		}
		return attributes;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, REAPackage.REA_POLICY_RELATION__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case REAPackage.REA_POLICY_RELATION__ATTRIBUTES:
				return ((InternalEList<?>)getAttributes()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case REAPackage.REA_POLICY_RELATION__OPERATIONAL_ENTITY:
				if (resolve) return getOperationalEntity();
				return basicGetOperationalEntity();
			case REAPackage.REA_POLICY_RELATION__POLICY_ENTITY:
				if (resolve) return getPolicyEntity();
				return basicGetPolicyEntity();
			case REAPackage.REA_POLICY_RELATION__POLICY_RELATIONSHIP_TYPE:
				return getPolicyRelationshipType();
			case REAPackage.REA_POLICY_RELATION__ATTRIBUTES:
				return getAttributes();
			case REAPackage.REA_POLICY_RELATION__NAME:
				return getName();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case REAPackage.REA_POLICY_RELATION__OPERATIONAL_ENTITY:
				setOperationalEntity((REAOperationalEntity)newValue);
				return;
			case REAPackage.REA_POLICY_RELATION__POLICY_ENTITY:
				setPolicyEntity((REAPolicyEntity)newValue);
				return;
			case REAPackage.REA_POLICY_RELATION__POLICY_RELATIONSHIP_TYPE:
				setPolicyRelationshipType((PolicyRelationshipType)newValue);
				return;
			case REAPackage.REA_POLICY_RELATION__ATTRIBUTES:
				getAttributes().clear();
				getAttributes().addAll((Collection<? extends REAAttribute>)newValue);
				return;
			case REAPackage.REA_POLICY_RELATION__NAME:
				setName((String)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case REAPackage.REA_POLICY_RELATION__OPERATIONAL_ENTITY:
				setOperationalEntity((REAOperationalEntity)null);
				return;
			case REAPackage.REA_POLICY_RELATION__POLICY_ENTITY:
				setPolicyEntity((REAPolicyEntity)null);
				return;
			case REAPackage.REA_POLICY_RELATION__POLICY_RELATIONSHIP_TYPE:
				setPolicyRelationshipType(POLICY_RELATIONSHIP_TYPE_EDEFAULT);
				return;
			case REAPackage.REA_POLICY_RELATION__ATTRIBUTES:
				getAttributes().clear();
				return;
			case REAPackage.REA_POLICY_RELATION__NAME:
				setName(NAME_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case REAPackage.REA_POLICY_RELATION__OPERATIONAL_ENTITY:
				return operationalEntity != null;
			case REAPackage.REA_POLICY_RELATION__POLICY_ENTITY:
				return policyEntity != null;
			case REAPackage.REA_POLICY_RELATION__POLICY_RELATIONSHIP_TYPE:
				return policyRelationshipType != POLICY_RELATIONSHIP_TYPE_EDEFAULT;
			case REAPackage.REA_POLICY_RELATION__ATTRIBUTES:
				return attributes != null && !attributes.isEmpty();
			case REAPackage.REA_POLICY_RELATION__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (policyRelationshipType: ");
		result.append(policyRelationshipType);
		result.append(", name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //REAPolicyRelationImpl
